package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.MeitanMapper;
import work.xiaohong.gupiao.pojo.Meitan;
import work.xiaohong.gupiao.service.MeitanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MeitanServiceImpl implements MeitanService {

    @Autowired
    private MeitanMapper meitanMapper;


    /**
     * 条件+分页查询Meitan
     * @param meitan 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Meitan> findPage(Meitan meitan, int page, int size){
        // 构建查询条件
        QueryWrapper<Meitan> queryWrapper = new QueryWrapper<Meitan>(meitan);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return meitanMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Meitan
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Meitan> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return meitanMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Meitan
     * @param meitan
     * @return
     */
    @Override
    public List<Meitan> findList(Meitan meitan){
        // 构建查询条件
        QueryWrapper<Meitan> queryWrapper = new QueryWrapper<Meitan>(meitan);
        // 查询数据
        return meitanMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Meitan
     * @param id
     */
    @Override
    public void delete(Integer id){
        meitanMapper.deleteById(id);
    }

    /**
     * 根据ID修改Meitan
     * @param meitan
     */
    @Override
    public void update(Meitan meitan){
        meitanMapper.updateById(meitan);
    }

    /**
     * 增加Meitan
     * @param meitan
     */
    @Override
    public void add(Meitan meitan){
        meitanMapper.insert(meitan);
    }

    /**
     * 根据ID查询Meitan
     * @param id
     * @return
     */
    @Override
    public Meitan findById(Integer id){
        return  meitanMapper.selectById(id);
    }

    /**
     * 查询全部Meitan数据
     * @return
     */
    @Override
    public List<Meitan> findAll() {
        return meitanMapper.selectList(null);
    }
}
